package com.shop.controller;


import com.shop.entity.PmsCategory;
import com.shop.service.PmsCategoryService;
import com.shop.vo.ResultJson;
import com.sun.org.apache.xpath.internal.operations.Bool;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 分类表 前端控制器
 * </p>
 *
 * @author lpx610
 * @since 2023-11-03
 */
@RestController
@RequestMapping("/pmsCategory")
public class PmsCategoryController {

    @Resource
    private PmsCategoryService pmsCategoryService;

    @GetMapping("/list")
    public ResultJson<List<PmsCategory>> list() {
        return ResultJson.success(pmsCategoryService.getAll());
    }

    @GetMapping("/getById")
    public ResultJson<PmsCategory> getById(String id) {
        return ResultJson.success(pmsCategoryService.getById(id));
    }

    @PostMapping("/add")
    public ResultJson<Boolean> add(String name, String parentId, Integer level) {
        return ResultJson.success(pmsCategoryService.add(name, parentId, level), "添加分类成功");
    }

    @PostMapping("/update")
    public ResultJson<Boolean> update(String id, String name) {
        return ResultJson.success(pmsCategoryService.update(id, name), "修改分类成功");
    }

    @GetMapping("/delete")
    public ResultJson<Boolean> delete(String id, Boolean active) {
        return ResultJson.success(pmsCategoryService.delete(id, active), active ? "启用分类成功" : "禁用分类成功");
    }

}
